import { WeeklyReportItem, WeeklyReportQueryParams, PaginatedResponse } from './types';

// 模拟数据 - 在实际开发中应替换为真实API请求
const mockData: WeeklyReportItem[] = [
  {
    projectId: 'XM-20240428001',
    projectName: '某某项目A',
    isHighRisk: '否',
    confirmOnlineDate: '2025-04-28',
    planOnlineDate: '2025-04-28',
    onlinePeriod: '上午',
    manager: '张三',
    team: 'A团队',
    department: '研发部',
    relatedProject: '关联项目A',
    groupLeader: '李四',
    allowDCAdjust: '是'
  },
  {
    projectId: 'XM-20240428002',
    projectName: '某某项目B',
    isHighRisk: '是',
    confirmOnlineDate: '2025-04-29',
    planOnlineDate: '2025-04-29',
    onlinePeriod: '下午',
    manager: '王五',
    team: 'B团队',
    department: '测试部',
    relatedProject: '关联项目B',
    groupLeader: '赵六',
    allowDCAdjust: '否'
  },
];

/**
 * 获取周报表数据
 * @param params 查询参数
 * @returns 分页数据
 */
export const fetchReportData = async (params: WeeklyReportQueryParams): Promise<PaginatedResponse<WeeklyReportItem>> => {
  // 在实际环境中，这里应该是发起网络请求的代码
  // 例如：return request('/api/weekly-report', { params });
  
  // 模拟网络请求延迟
  await new Promise(resolve => setTimeout(resolve, 500));
  
  // 这里仅做模拟，实际项目中应改为真实API调用
  const { page = 1, pageSize = 10 } = params;
  
  // 模拟根据搜索条件过滤数据
  let filteredData = [...mockData];
  
  if (params.projectId) {
    filteredData = filteredData.filter(item => 
      item.projectId.toLowerCase().includes(params.projectId!.toLowerCase())
    );
  }
  
  if (params.teamName) {
    filteredData = filteredData.filter(item => 
      item.team.includes(params.teamName!)
    );
  }
  
  if (params.manager) {
    filteredData = filteredData.filter(item => 
      item.manager.includes(params.manager!)
    );
  }
  
  // 计算分页数据
  const start = (page - 1) * pageSize;
  const end = start + pageSize;
  const list = filteredData.slice(start, end);
  
  return {
    list,
    total: filteredData.length,
    page,
    pageSize
  };
};

/**
 * 导出Excel
 * @param params 查询参数
 */
export const exportToExcel = async (params: WeeklyReportQueryParams): Promise<void> => {
  // 实际项目中，这里应该调用后端导出接口
  console.log('导出Excel', params);
}; 